//猜数字游戏
import java.util.Scanner;
import java.util.Random;

public class GuessNumber {
    public static void main1(String[] args) {
        Scanner reader = new Scanner(System.in);
        Random random = new Random();
        System.out.println("系统随机给出 [0,100] 中的一个数，请尝试猜出它");
        int ret = random.nextInt(100) + 1;
        //System.out.println(ret);  //测试语句
        int num = 0;

        int n = 0;  //猜数次数
        long begin = System.currentTimeMillis();    //开始时间
        while(true)
        {
            System.out.print("请输入你的猜测:");
            num = reader.nextInt();
            n++;    //输入一次，算猜一次

            if(num < ret)
                System.out.println("猜小了");
            else if(num > ret)
                System.out.println("猜大了");
            else
                break;
        }
        long end = System.currentTimeMillis();  //结束时间

        System.out.printf("恭喜你猜到了! 目标数为:%d 共计猜了%d次，耗时:%d秒\n", ret, n, (end - begin) / 1000);
    }
}